package com.nulldev.util.graphics.renderIt.ginterfaces.stub;

import java.awt.FontMetrics;
import java.io.File;
import com.nulldev.util.VariableAPI.ArrayUtils;
import com.nulldev.util.graphics.renderIt.api.renderItGraphicsInterface;
import com.nulldev.util.graphics.renderIt.api.core.RITFont;
import com.nulldev.util.graphics.renderIt.api.envcaps.renderItOperations;
import com.nulldev.util.graphics.renderIt.api.math.Vector2f;
import com.nulldev.util.graphics.renderIt.api.math.Vector4f;
import com.nulldev.util.graphics.renderIt.exts.awt.fonts.AWTFont;
import com.nulldev.util.graphics.renderIt.renderer.global.rColor;
import com.nulldev.util.gui.swingAPI.Swing;
import com.nulldev.util.io.IOUtils;
import com.nulldev.util.manage.Version;

public class StubGraphicsInterface extends renderItGraphicsInterface {

	private static final Version BACKEND_VERSION = new Version(0, 0, 999);
	private static final renderItOperations[] core_ops = new renderItOperations[]
		{ renderItOperations.RIT_EXT_basic_drawing, renderItOperations.RIT_EXT_basic_shapes, renderItOperations.RIT_EXT_viewport_info,
				renderItOperations.RIT_EXT_viewport_offset, renderItOperations.RIT_EXT_versions, renderItOperations.RIT_SWING_panel_control,
				renderItOperations.RIT_EXT_color, renderItOperations.RIT_canvas_clear, renderItOperations.RIT_font_file_formats,
				renderItOperations.RIT_2D_basic_drawing, renderItOperations.RIT_3D_matrix, renderItOperations.RIT_2D_matrix, renderItOperations.RIT_2D_vector,
				renderItOperations.RIT_3D_vector, renderItOperations.RIT_3D_psuedo_basic_drawing, renderItOperations.RIT_RIO_closable,
				renderItOperations.RIT_font_ops, renderItOperations.RIT_font_create, renderItOperations.RIT_text_string,
				renderItOperations.RIT_text_anti_aliasing, renderItOperations.RIT_canvas_clear, renderItOperations.RIT_AWT_font_conversion,
				renderItOperations.RIT_text_string_scalable, renderItOperations.RIT_SWING_image_draw, renderItOperations.RIT_EXT_viewport_control,
				renderItOperations.RIT_text_string_scalable_offset,

				/* GL stuff */

				renderItOperations.GL_compat_vectors, renderItOperations.GL_compat_vertex, renderItOperations.GL_compat_direction,

				/* WM stuff */

				renderItOperations.RIT_WM_window, renderItOperations.RIT_WM_window_position, renderItOperations.RIT_nullutil_swing_api };
	private final renderItOperations[] SUPPORTED_OPS = core_ops;
	private final renderItGraphicsInterface passthrough;

	public StubGraphicsInterface() {
		this.passthrough = null;
	}

	public StubGraphicsInterface(final renderItGraphicsInterface pt) {
		this.passthrough = pt;
	}

	@Override
	public boolean supportsOperations(renderItOperations operation) {
		return ArrayUtils.contains(this.SUPPORTED_OPS, operation);
	}

	@Override
	public renderItOperations[] supportedOperations() {
		return this.SUPPORTED_OPS;
	}

	@Override
	public Object rit_get(final int RIT_CONSTANT) {
		switch (RIT_CONSTANT) {
			case RIT_RENDERER_NAME:
				return "Stub";
			case RIT_RENDERER_VENDOR:
				return "nullUtil";
			case RIT_RENDERER_VERSION:
				return BACKEND_VERSION.asVersionString();
			case RIT_BACKEND_GET_CONTEXT_BEHAVIOUR:
				return RIT_BACKEND_BEHAVIOUR_NO_CONTEXT;
			case RIT_BACKEND_GET_COMPAT_IMAGE_MODE:
			case RIT_BACKEND_GET_2D_PREFERRED_HINT:
				return RIT_TRUE;
			case RIT_BACKEND_GET_3D_PREFERRED_HINT:
				return RIT_TRUE;
			case RIT_BACKEND_GET_RENDERER_TYPE:
				return RIT_BACKEND_RENDERER_TYPE_HYBRID;
			case RIT_BACKEND_GET_BUFFERING_BEHAVIOUR:
				return RIT_DIRECT_SCANOUT;
			case RIT_BACKEND_GET_RENDER_DIRECTION:
				return RIT_BACKEND_RENDER_DIRECTION_TOP_LEFT;
			case RIT_GET_SCANOUT_METHOD:
				return RIT_DIRECT_SCANOUT;
			default:
				return RIT_NOT_SUPPORTED;
		}
	}

	@Override
	public Object rit_set(int RIT_CONSTANT, Object RIT_OBJECT) {
		return RIT_NOT_SUPPORTED;
	}

	/* RIT_EXT_basic_drawing */

	@Override
	public void bd_drawRect(final int x, final int y, final int w, final int h) {
	}

	@Override
	public void bd_drawRect(final int x, final int y, final int w, final int h, final rColor color) {
	}

	@Override
	public void bd_fillRect(final int x, final int y, final int w, final int h) {
	}

	@Override
	public void bd_fillRect(final int x, final int y, final int w, final int h, final rColor color) {
	}

	@Override
	public void bd_putPixel(final int x, final int y) {
	}

	@Override
	public void bd_putPixel(final int x, final int y, final rColor color) {
	}

	@Override
	public void bd_drawLine(final int x1, final int y1, final int x2, final int y2) {
	}

	@Override
	public void bd_drawLine(final int x1, final int y1, final int x2, final int y2, final rColor color) {
	}

	/* RIT_EXT_basic_shapes */

	public void bd_drawOval(final int x, final int y, final int width, final int height) {
	}

	public void bd_drawOval(final int x, final int y, final int width, final int height, final rColor color) {
	}

	public void bd_drawCircle(final int x, final int y, final int r) {
	}

	public void bd_drawCircle(final int x, final int y, final int r, final rColor color) {
	}

	public void bd_fillOval(final int x, final int y, final int width, final int height) {
	}

	public void bd_fillOval(final int x, final int y, final int width, final int height, final rColor color) {
	}

	public void bd_fillCircle(final int x, final int y, final int r) {
	}

	public void bd_fillCircle(final int x, final int y, final int r, final rColor color) {
	}

	/* RIT_EXT_viewport_info */

	@Override
	public int viewport_getWidth() {
		if (this.passthrough != null)
			return this.passthrough.viewport_getWidth();
		else
			return 0;
	}

	@Override
	public int viewport_getHeight() {
		if (this.passthrough != null)
			return this.passthrough.viewport_getHeight();
		else
			return 0;
	}

	/* RIT_EXT_viewport_offset */

	@Override
	public int viewport_getXOffset() {
		return 0;
	}

	@Override
	public int viewport_getYOffset() {
		return 0;
	}

	/* RIT_WM_window_position */

	@Override
	public void wm_setWindowPosX(final int x) {
	}

	@Override
	public void wm_setWindowPosY(final int y) {
	}

	@Override
	public int wm_getPosX() {
		if (this.passthrough != null)
			return this.wm_getPosX();
		else
			return RIT_NOT_SUPPORTED;
	}

	@Override
	public int wm_getPosY() {
		if (this.passthrough != null)
			return this.wm_getPosY();
		else
			return RIT_NOT_SUPPORTED;
	}

	/* RIT_EXT_versions */

	@Override
	public String backend_version() {
		return BACKEND_VERSION.asVersionString();
	}

	/* RIT_SWING_panel_control */

	@Override
	public void swing_panel_doubleBuffer(final boolean doubleBuffer) {
	}

	@Override
	public boolean swing_panel_isDoubleBuffered() {
		return false;
	}

	@Override
	public void swing_panel_setSize(final int width, final int height) {
	}

	@Override
	public int swing_panel_getSizeX() {
		return 0;
	}

	@Override
	public int swing_panel_getSizeY() {
		return 0;
	}

	/* RIT_EXT_color */

	@Override
	public rColor getColor() {
		return rColor.white;
	}

	@Override
	public void setColor(final rColor color) {
		if (this.passthrough != null)
			this.passthrough.setColor(color);
	}

	@Override
	public void setColor(final int color) {
		if (this.passthrough != null)
			this.passthrough.setColor(color);
	}

	@Override
	public void setColor(final int r, final int g, final int b) {
		if (this.passthrough != null)
			this.passthrough.setColor(r, g, b);
	}

	@Override
	public void setColor(final double r, final double g, final double b, final double a) {
		if (this.passthrough != null)
			this.passthrough.setColor(r, g, b, a);
	}

	/* RIT_nullutil_swing_api */

	@Override
	public void nullutil_swing_center() {
	}

	@Override
	public int nullutil_swing_getRefreshRate() {
		return (int) Swing.refreshRate();
	}

	@Override
	public int nullutil_swing_stringWidth(final Object fontMetrics, final String line) {
		this.checkValidObject(RIT_VALUE_TYPE_AWT_FONT_METRICS, fontMetrics);
		this.checkValidObject(RIT_VALUE_TYPE_STRING, line);
		return Swing.stringWidth((FontMetrics) fontMetrics, line);
	}

	@Override
	public boolean nullutil_swing_isUsingHWAccel() {
		return Swing.isUsingHWAccel();
	}

	/* RIT_font_file_formats */

	@Override
	public boolean supportsFontFileFormat(final int fontFormat) {
		this.checkValidInt(RIT_VALUE_TYPE_FONT_FORMAT, fontFormat);
		switch (fontFormat) {
			case RIT_FONT_FORMAT_OTF:
			case RIT_FONT_FORMAT_TTF:
				return true;
			default:
				return false;
		}
	}

	/* RIT_2D_basic_drawing */

	@Override
	public void rit_2d_drawPoint(final Vector2f vec) {
	}

	@Override
	public void rit_2d_drawLine(final Vector2f start, final Vector2f end) {
	}

	@Override
	public void rit_2d_drawRect(final Vector2f pos, final int width, final int height) {
	}

	@Override
	public void rit_2d_drawRect(final Vector2f pos, final Vector2f dim) {
	}

	@Override
	public void rit_2d_fillRect(final Vector2f pos, final int width, final int height) {
	}

	@Override
	public void rit_2d_fillRect(final Vector2f pos, final Vector2f dim) {
	}

	/* RIT_3D_psuedo_basic_drawing */

	@Override
	public void rit_3d_draw_hRect(final Vector4f rect, final boolean raise) {
	}

	@Override
	public void rit_3d_draw_hRect(final Vector2f pos, final int width, final int height, final boolean raise) {
	}

	@Override
	public void rit_3d_fill_hRect(final Vector4f rect, final boolean raise) {
	}

	@Override
	public void rit_3d_fill_hRect(final Vector2f pos, final int width, final int height, final boolean raise) {
	}

	/* GL_compat_vertex */

	@Override
	public void glVertex2f(final float x, final float y) {
	}

	@Override
	public void glVertex2d(final double x, final double y) {
	}

	@Override
	public void glVertex2i(final int x, final int y) {
	}

	@Override
	public void glVertex2s(final short x, final short y) {
	}

	/* GL_compat_vectors */

	@Override
	public void glTreatVectorsAs(final int type) {
	}

	@Override
	public int glGetVectorTreatment() {
		return GL_VECTOR_TYPE_COORD_FLOAT;
	}

	/* GL_compat_direction */

	public int glCompatGetDirection() {
		return GL_DIRECTION_TYPE_SWING;
	}

	public void glCompatSetDirection(final int type) {
	}

	/* RIT_RIO_closeable */

	@Override
	public void closeOperations() {
	}

	/* RIT_font_ops */

	@Override
	public void font_destroy(final RITFont font) {
		IOUtils.closeQuietly(font);
	}

	@Override
	public int font_get_format(final RITFont font) {
		return font.getFormat();
	}

	@Override
	public RITFont font_clone(final RITFont font, final int size, final int style) {
		return font.deriveToSize(size).deriveToStyle(style);
	}

	@Override
	public RITFont font_clone(final RITFont font, final float size, final int style) {
		return font.deriveToSize(size).deriveToStyle(style);
	}

	@Override
	public RITFont font_clone(final RITFont font, final int size) {
		return font.deriveToSize(size);
	}

	@Override
	public RITFont font_clone(final RITFont font, final float size) {
		return font.deriveToSize(size);
	}

	/* RIT_font_create */

	@Override
	public RITFont font_create(final String name, final int size, final int style) {
		return AWTFont.create(name, size, style);
	}

	@Override
	public RITFont font_create(final String name, final float size, final int style) {
		return AWTFont.create(name, size, style);
	}

	@Override
	public RITFont font_create(final String name, final int size) {
		return AWTFont.create(name, size);
	}

	@Override
	public RITFont font_create(final String name, final float size) {
		return AWTFont.create(name, size);
	}

	@Override
	public RITFont font_create(final File file) {
		return AWTFont.create(file);
	}

	/* RIT_text_string */

	@Override
	public void text_string(final String text, final int x, final int y, final RITFont font) {
	}

	@Override
	public void text_string(final String text, final int x, final int y, final RITFont font, final rColor color) {
	}

	@Override
	public void text_shadowedString(final String text, final int x, final int y, final RITFont font) {
	}

	@Override
	public void text_shadowedString(final String text, final int x, final int y, final RITFont font, final rColor c) {
	}

	/* RIT_text_string_scalable */

	@Override
	public int text_scalable(final String text, final int x, final int y, final RITFont font) {
		return 0;
	}

	@Override
	public int text_scalable(final String text, final int x, final int y, final RITFont font, final rColor color) {
		return 0;
	}

	/* RIT_text_string_scalable_offset */

	@Override
	public int text_scalable(final String text, final int x, final int y, final int offset, final RITFont font) {
		return 0;
	}

	@Override
	public int text_scalable(final String text, final int x, final int y, final int offset, final RITFont font, final rColor color) {
		return 0;
	}

	/* RIT_text_anti_aliasing */

	@Override
	public boolean text_isAAPresent() {
		if (this.passthrough != null)
			return this.passthrough.text_isAAPresent();
		else
			return false;
	}

	@Override
	public void text_setAAPresence(final boolean value) {
	}

	/* RIT_canvas_clear */

	@Override
	public void canvas_clear(final int x, final int y, final int width, final int height) {
	}

	@Override
	public void canvas_clear(final int x, final int y, final int width, final int height, final rColor color) {
	}

	@Override
	public void canvas_clear(final Vector4f v4f) {
	}

	@Override
	public void canvas_clear(final Vector4f v4f, final rColor color) {
	}

	@Override
	public void canvas_clear(final Vector2f pos, final Vector2f dim) {
	}

	@Override
	public void canvas_clear(final Vector2f pos, final Vector2f dim, final rColor color) {
	}

	/* RIT_AWT_font_conversion */

	@Override
	public RITFont awt_make_font(final Object font) {
		if (this.passthrough != null)
			return this.passthrough.awt_make_font(font);
		else
			return null;
	}

	/* RIT_SWING_image_draw */

	@Override
	public void swing_drawImage(final Object image, final int x, final int y) {
	}

	@Override
	public void swing_drawImage(final Object image, final int x, final int y, final int width, final int height) {
	}

	@Override
	public void swing_drawImage(final Object image, final int x, final int y, final int width, final int height, final Object observer) {
	}

	/* RIT_EXT_viewport_control */

	@Override
	public boolean viewport_requestSize(final int width, final int height) {
		if (height < 0 || width < 0)
			return false;
		if (this.passthrough == null)
			return false;
		return this.passthrough.viewport_requestSize(width, height);
	}

	@Override
	public boolean viewport_requestHeight(final int height) {
		if (height < 0)
			return false;
		if (this.passthrough == null)
			return false;
		return this.passthrough.viewport_requestHeight(height);
	}

	@Override
	public boolean viewport_requestWidth(final int width) {
		if (width < 0)
			return false;
		if (this.passthrough == null)
			return false;
		return this.passthrough.viewport_requestHeight(width);
	}

	/* WINDOWS_invalidate_surface */

	@Override
	public void windows_invalidateSurface() {
		if (this.passthrough == null)
			return;
		this.passthrough.windows_invalidateSurface();
	}
}
